package com.ofc.chart;

import java.util.LinkedList;
import java.util.Random;

import com.ofc.chart.element.Element;
import com.ofc.chart.element.Style;
import com.ofc.chart.element.Title;
import com.ofc.chart.element.XAxis;
import com.ofc.chart.element.YAxis;
import com.ofc.chart.element.YLegend;
import com.ofc.chart.model.Bar3D;
import com.ofc.chart.model.Template;

/**
 * Chart Json 测试类
 * 
 * @author zhangpeng
 * @date 2012-12-6
 */
public class Test {
	public static void bar3DJsonTest() {
		ChartJsonService service = new ChartJsonService();

		Title title = new Title();
		Style style = new Style();
		style.setFontSize("20px");
		style.setColor("#0000ff");
		style.setFontFamily("Verdana");
		style.setTextAlign("center");
		title.setText("批次信息总量");//
		title.setStyle(style);

		YLegend ylegend = new YLegend();
		Style style1 = new Style();
		style1.setFontSize("12px");
		style1.setColor("#736AFF");
		style1.setPadding("10px");
		ylegend.setText("Area");//
		ylegend.setStyle(style1);

		XAxis xaxis = new XAxis();
		xaxis.setStroke(1);
		xaxis.setTickHeight(10);
		xaxis.setColour("#909090");
		xaxis.setGridColour("#ADB5C7");
		LinkedList<String> labels = new LinkedList<String>();
		for (int i = 2000; i <= 2012; i++) {
			labels.add(i + "");
		}
		xaxis.setLabels(labels);//
		xaxis.set3d(10);

		YAxis yaxis = new YAxis();
		yaxis.setStroke(4);
		yaxis.setTickHeight(3);
		yaxis.setColour("#909090");
		yaxis.setGridColour("#ADB5C7");
		yaxis.setOffset(0);
		yaxis.setMax(new Double(20));

		LinkedList<Element> elements = new LinkedList<Element>();
		Random rnd = new Random();
		Element e1 = new Element();
		LinkedList<String> colours1 = new LinkedList<String>();
		colours1.add("#D54C78");
		e1.setType("bar_3d");
		e1.setAlpha(new Float(0.8));
		e1.setColours(colours1);
		e1.setText("申请用地总面积");//
		e1.setFontSize(12);
		LinkedList<String> values1 = new LinkedList<String>();
		for (int i = 0; i < 13; i++) {
			values1.add(rnd.nextInt(20) + "");
		}
		e1.setValues(values1);//
		elements.add(e1);

		Element e2 = new Element();
		LinkedList<String> colours2 = new LinkedList<String>();
		colours2.add("#3334AD");
		e2.setType("bar_3d");
		e2.setAlpha(new Float(0.8));
		e2.setColours(colours2);
		e2.setText("新增建设用地");//
		e2.setFontSize(12);
		LinkedList<String> values2 = new LinkedList<String>();
		for (int i = 0; i < 13; i++) {
			values2.add(rnd.nextInt(20) + "");
		}
		e2.setValues(values2);//
		elements.add(e2);

		Element e3 = new Element();
		LinkedList<String> colours3 = new LinkedList<String>();
		colours3.add("#639F45");
		e3.setType("bar_3d");
		e3.setAlpha(new Float(0.8));
		e3.setColours(colours3);
		e3.setText("未利用地");//
		e3.setFontSize(12);
		LinkedList<String> values3 = new LinkedList<String>();
		for (int i = 0; i < 13; i++) {
			values3.add(rnd.nextInt(20) + "");
		}
		e3.setValues(values3);//
		elements.add(e3);

		Bar3D bar3D = new Bar3D();
		bar3D.setTitle(title);
		bar3D.setYlegend(ylegend);
		bar3D.setXaxis(xaxis);
		bar3D.setYaxis(yaxis);
		bar3D.setElements(elements);

		String json = service.buildBar3DJson(bar3D);
		System.out.println(json);
	}

	public static void bar3DTemplateTest() {
		ChartJsonTemplate temp = new ChartJsonTemplate();
		LinkedList<String> elementText = new LinkedList<String>();
		elementText.add("面积1");
		elementText.add("面积2");

		LinkedList<String> valueField = new LinkedList<String>();
		valueField.add("MJ1");
		valueField.add("MJ2");

		Template template = new Template();
		template.setXtitle("面积柱状图");
		template.setYtitle("Area");
		template.setElementText(elementText);
		template.setKeyField("YEAR");
		template.setValueField(valueField);

		LinkedList<String> labels = new LinkedList<String>();
		labels.add("2001");
		labels.add("2002");
		labels.add("2003");

		LinkedList<LinkedList<String>> values = new LinkedList<LinkedList<String>>();
		LinkedList<String> valueList1 = new LinkedList<String>();
		valueList1.add("110");
		valueList1.add("130");
		valueList1.add("80");

		LinkedList<String> valueList2 = new LinkedList<String>();
		valueList2.add("201");
		valueList2.add("150");
		valueList2.add("97");

		values.add(valueList1);
		values.add(valueList2);

		double maxValue = 400;

		Bar3D bar3D = temp.getBar3DTemplate(template.getXtitle(),
				template.getYtitle(), labels, maxValue, elementText, values);
		ChartJsonService service = new ChartJsonService();
		String json = service.buildBar3DJson(bar3D);
		System.out.println(json);
	}

	public static void main(String[] args) {
		// bar3DJsonTest();
		bar3DTemplateTest();
	}
}
